package com.sywb.chuangyebao.bean;

import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.sywb.chuangyebao.Constants;

import java.util.HashMap;
import java.util.List;

public class User {

    public int user_id;// 用户ID
    public String display_name;// 名称
    public String avatar;// 头像
    // public int user_group_id;// 用户角色
    public String user_role; // 用户角色（多选）：0=未知 1=普通用户 2=达人  3=导师（专家） 5=创业顾问 6=项目号 7=服务商
    public int fans_num;// 粉丝数
    public int answer_num;// 回答数
    public String signature;// 签名
    public List<GoodAtBean> good_at;// 擅长领域信息

    public boolean is_follow;// 是否关注
//    public boolean isInvited;
    public boolean isSelected;

    public String getShowName() {
        if (!TextUtils.isEmpty(display_name)) {
            return display_name;
        }
        return "";
    }

    public String getShowAvatar() {
        return avatar;
    }

    public int getUserRole() {
        if (!TextUtils.isEmpty(user_role)) {
            HashMap<Integer, String> userRole = JSON.parseObject(user_role, new TypeReference<HashMap<Integer, String>>() {
            });
            if (userRole.containsKey(Constants.USER_TYPE_V)) {
                return Constants.USER_TYPE_V;
            } else if (userRole.containsKey(Constants.USER_TYPE_PROJECT)) {
                return Constants.USER_TYPE_PROJECT;
            } else if (userRole.containsKey(Constants.USER_TYPE_SERVICE)) {
                return Constants.USER_TYPE_SERVICE;
            } else if (userRole.containsKey(Constants.USER_TYPE_TUTOR)) {
                return Constants.USER_TYPE_TUTOR;
            }
        }
        return Constants.USER_TYPE_NORMAL;
    }

    public String getGoodAtString() {
        StringBuilder builder = new StringBuilder();
        if (good_at != null && good_at.size() > 0) {
            for (GoodAtBean goodAtBean : good_at) {
                builder.append(goodAtBean.name).append("、");
            }
            return builder.toString().substring(0, builder.length() - 1);
        } else {
            return builder.toString();
        }
    }

}
